package ru.pb.game.network.engine.client.packets.receivable;

import ru.pb.game.data.xml.holders.ChannelHolder;
import ru.pb.game.network.clients.GameClient;
import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.network.engine.client.packets.sendable.PROTOCOL_LOBBY_LEAVE_ACK;
import ru.pb.game.objects.model.CHANNEL;
import ru.pb.game.objects.model.players.Player;

public class PROTOCOL_LOBBY_LEAVE_REQ extends FromClientToGameServerPacket
{
	public PROTOCOL_LOBBY_LEAVE_REQ()
	{

	}

	@Override
	public void readImpl()
	{

	}

	@Override
	public void runImpl()
	{
		GameClient cl = getClient();
		if(cl == null)
			return;

		Player p = getPlayer();
		CHANNEL ch = ChannelHolder.getChannel(cl.getChannelId());
		if(ch != null && p != null)
		{
			if(ch.getAllPlayers().contains(p.getObjectId()))
			{
				ch.removePlayer(p);
			}
		}
		p.sendPacket(new PROTOCOL_LOBBY_LEAVE_ACK());
	}
}